import 'package:biosphere/bean/MainPageEnum.dart';
import 'package:biosphere/bean/PageIndexBean.dart';
import 'package:biosphere/page/main/check_manage/view.dart';
import 'package:biosphere/page/main/main_home/view.dart';
import 'package:biosphere/page/main/mine/view.dart';
import 'package:flutter/cupertino.dart';
import 'package:get/get.dart';

import 'knowledge/view.dart';
import 'state.dart';

class MainLogic extends GetxController {
  final MainState state = MainState();
  var pageController = PageController(initialPage: 0);
  @override
  void onInit() {
    super.onInit();
    state.pages.addAll([
      PageIndexBean(
          name: MainPageEnum.circle.name,
          page: const MainHomePage(),
          bottom: BottomNavigationBarItem(
            label: MainPageEnum.circle.label,
            icon: Obx(() {
              return Image.asset(
                state.currentIndex.value == 0
                    ? "assets/main/biosphere_selected.png"
                    : "assets/main/biosphere.png",
                scale: 6,
              );
            }),
          )),
      PageIndexBean(
          name: MainPageEnum.arch.name,
          page: const CheckManagePage(),
          bottom: BottomNavigationBarItem(
            label: MainPageEnum.arch.label,
            icon: Obx(() {
              return Image.asset(
                state.currentIndex.value == 1
                    ? "assets/main/arch_selected.png"
                    : "assets/main/arch.png",
                scale: 6,
              );
            }),
          )),
      PageIndexBean(
          name: MainPageEnum.find.name,
          page: const KnowledgePage(),
          bottom: BottomNavigationBarItem(
            label: MainPageEnum.find.label,
            icon: Obx(() {
              return Image.asset(
                state.currentIndex.value == 2
                    ? "assets/main/find_selected.png"
                    : "assets/main/find.png",
                scale: 6,
              );
            }),
          )),
      PageIndexBean(
          name: MainPageEnum.mine.name,
          page: const MinePage(),
          bottom: BottomNavigationBarItem(
            label: MainPageEnum.mine.label,
            icon: Obx(() {
              return Image.asset(
                state.currentIndex.value == 3
                    ? "assets/main/mine_selected.png"
                    : "assets/main/mine.png",
                scale: 6,
              );
            }),
          ))
    ]);
  }

  void changePageTo(int i) {
    state.currentIndex.value = i;
    pageController.animateToPage(i,
        duration: const Duration(milliseconds: 200), curve: Curves.linear);
  }
}
